<template>
  <div class="header-wrapper">
    <div class="logo-title">{{$t('appName')}}</div>
    <div class="header-navs">
      <span class="link-btn" @click="changeLanguage('zh')">中文</span>
      <span class="link-btn" @click="changeLanguage('en')">ENG</span>
      <el-button size="small" class="login-btn" v-if="!uid" @click="handleGotoLogin">{{$t('login.login')}}</el-button>
      <span class="link-btn" v-else @click="handleGotoDashboard">{{userInfo.nickname}}</span>
    </div>
  </div>
  <div class="carousel-box">
    <el-carousel height="auto" :autoplay="true" :interval="carInterval" motion-blur>
      <el-carousel-item class="img-item">
        <img style="width: 100%;" src="/assets/images/home-bar-pic-1.png" />
        <div class="carousel-info">
          <div class="title-box">
            <span>{{$t('index.bar.navTitle1')}}</span>
            <div class="logo"></div>
          </div>
          <div class="desc">{{$t('index.bar.navDesc1')}}</div>
          <el-button type="primary">{{$t('index.bar.learnMore1')}}</el-button>
        </div>
      </el-carousel-item>
      <el-carousel-item class="img-item">
        <img style="width: 100%;" src="/assets/images/home-bar-pic-1.png" />
        <div class="carousel-info">
          <div class="title-box">
            <span>{{$t('index.bar.navTitle1')}}</span>
            <div class="logo"></div>
          </div>
          <div class="desc">{{$t('index.bar.navDesc1')}}</div>
          <el-button type="primary">{{$t('index.bar.learnMore1')}}</el-button>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
  <div class="wrapper-title">{{$t('index.feature.title')}}</div>
  <div class="wrapper-features">
    <div class="feature-item" @click="handleGotoHot">
      <div class="icon"></div>
      <div class="text">{{$t('index.feature.text1')}}</div>
    </div>
    <div class="feature-item" @click="handleGotoAiSearch">
      <div class="icon"></div>
      <div class="text">{{$t('index.feature.text2')}}</div>
    </div>
    <div class="feature-item">
      <div class="icon"></div>
      <div class="text">{{$t('index.feature.text3')}}</div>
    </div>
    <div class="feature-item">
      <div class="icon"></div>
      <div class="text">{{$t('index.feature.text4')}}</div>
    </div>
    <div class="feature-item">
      <div class="icon"></div>
      <div class="text">{{$t('index.feature.text5')}}</div>
    </div>
    <div class="feature-item">
      <div class="icon"></div>
      <div class="text">{{$t('index.feature.text6')}}</div>
    </div>
  </div>
  <div class="footer-wrapper">
    <footer-comp></footer-comp>
  </div>
</template>

<script setup>
import {ref} from 'vue'
import {useRouter} from "vue-router";
import {useI18n} from "vue-i18n";
import FooterComp from '../components/footer.vue'
import common from "~/common/common.js";
import api from "~/api/index.js";
const router = useRouter()
const user = common.getLocalUser()
const uid = user.userId || ''
const carInterval = ref(500)
setTimeout(() => {
  carInterval.value = 3000
}, 1000)
const { locale } = useI18n();

const changeLanguage = (val) => {
  locale.value = val;
};
const handleGotoLogin = () => {
  router.replace('/login')
}
const handleGotoDashboard = () => {
  router.push('/ds')
}
const handleGotoHot = () => {
  if (!uid) {
    ElMessage.error('请先登录')
    return
  }
  router.push('/ds/sci-hot')
}
const handleGotoAiSearch = () => {
  if (!uid) {
    ElMessage.error('请先登录')
    return
  }
  router.push('/ds/ai-search')
}
const userInfo = ref({
  nickname: ''
})
const getUserInfo = async () => {
  try {
    const res = await api.getUserInfo({uid})
    if (res && res.uid) {
      userInfo.value.nickname = res.nickname || `用户${res.uid}`
    }
  } catch(e) {
    console.log(e)
  }
}
if (uid) {
  getUserInfo()
}
</script>

<style scoped lang="scss">
.header-wrapper{
  position: relative;
  height: 4.4rem;
  background: #0F40F5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
}
.logo-title{
  height: 20px;
  line-height: 20px;
  color: rgba(255,255,255,1);
  font-size: 1.2rem;
  font-family: PingFangSC-bold;
}
.header-navs{
  display: flex;
  align-items: center;
  .login-btn{
    margin-left: 15px;
  }
}
.carousel-box{
  .img-item{
    height: unset;
    //min-height: 79.8rem;
  }
  .carousel-info{
    position: absolute;
    top: 20%;
    left: 10%;
    .title-box{
      display: flex;
      align-items: center;
      font-size: 4.4rem;
      color: #fff;
    }
    .logo{
      background: url("../assets/images/logo.png") no-repeat;
      background-size: 100% 100%;
      width: 4.7rem;
      height: 4.1rem;
      margin-left: 10px;
    }
    .desc{
      font-size: 2.4rem;
      color: #fff;
      margin-top: 5rem;
      margin-bottom: 2rem;
    }
  }
}
.wrapper-title{
  position: relative;
  padding: 4.2rem 0 3.7rem;
  height: 50px;
  line-height: 50px;
  color: rgba(51,51,51,1);
  font-size: 3.6rem;
  text-align: center;
  font-family: PingFangSC-bold;
}
.wrapper-features{
  padding: 0 4.8rem;
  position: relative;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.feature-item{
  text-align: center;
  position: relative;
  cursor: pointer;
  width: 48%;
  padding: 3rem 0;
  box-shadow: 0px 2px 6px 0px rgba(0,0,0,0.4);
  border: 1px solid rgba(187,187,187,1);
  margin-bottom: 3rem;
  .icon{
    display: inline-block;
    width: 5.0rem;
    height: 5.0rem;
    background-repeat: no-repeat;
    background-size: 100% 100%;
  }
  .text{
    padding-top: 1rem;
    font-size: 2rem;
    font-family: PingFangSC-regular;
  }
}
.feature-item:nth-child(1) {
  background-color: #FEFDD9;
  .icon{
    background-image: url("../assets/images/antOutline-start@1x.png");
  }
}
.feature-item:nth-child(2) {
  background-color: #DCFEFF;
  .icon{
    background-image: url("../assets/images/users-fas@1x.png");
  }
}
.feature-item:nth-child(3) {
  background-color: #E6FBC3;
  .icon{
    background-image: url("../assets/images/md-person_add@1x.png");
  }
}
.feature-item:nth-child(4) {
  background-color: #F0E6FD;
  .icon{
    background-image: url("../assets/images/iconPark-comments@1x.png");
  }
}
.feature-item:nth-child(5) {
  background-color: #D9EFFA;
  .icon{
    background-image: url("../assets/images/ze-edit@1x.png");
  }
}
.feature-item:nth-child(6) {
  background-color: rgb(250 237 238);
  .icon{
    background-image: url("../assets/images/ze-bar-chart@1x.png");
  }
}
.footer-wrapper{
  position: relative;
  height: 80px;
}
</style>
